package com.xindaoapp.happypet;

import java.util.LinkedList;
import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.lidroid.xutils.BitmapUtils;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.xindaoapp.happypet.activity.MyAttentionActivity;
import com.xindaoapp.happypet.activity.MyClubActivity;
import com.xindaoapp.happypet.activity.Search2Activity;
import com.xindaoapp.happypet.adapter.AttentionAdapter;
import com.xindaoapp.happypet.api.AddClient;
import com.xindaoapp.happypet.api.Address;
import com.xindaoapp.happypet.api.ConstantsValue;
import com.xindaoapp.happypet.bean.ClubC;
import com.xindaoapp.happypet.bean.ClubCInfo;
import com.xindaoapp.happypet.bean.ClubInfo;
import com.xindaoapp.happypet.bean.ClubInfo.Club;
import com.xindaoapp.happypet.utils.BitmapHelp;
import com.xindaoapp.happypet.view.CircleImageView;
import com.xindaoapp.happypet.view.MyGridView;

@SuppressLint("ShowToast")
public class LeftMenuFragement extends Fragment implements OnClickListener {

    @Override
    public void onResume() {
        initBenDi();
        initAttention();
        super.onResume();
    }

    private LinkedList<ClubC> attention;
    private AttentionAdapter attentionAdapter;

    private Context context;

    // LeftMenu wodeguanzhu
    private RelativeLayout left_menu_guanzhu;
    private MyGridView left_menu_guanzhu_content;
    private ImageView left_menu_guanzhu_image;

    // LeftMenu wangxingern
    private RelativeLayout left_menu_wangxingren;
    private MyGridView left_menu_wangxingren_content;
    private ImageView left_menu_wangxingren_image;

    // LeftMenu miaoxingren
    private RelativeLayout left_menu_miaoxingren;
    private MyGridView left_menu_miaoxingren_content;
    private ImageView left_menu_miaoxingren_image;

    // LeftMenu shuizu
    private RelativeLayout left_menu_shuizu;
    private MyGridView left_menu_shuizu_content;
    private ImageView left_menu_shuizu_image;

    // LeftMenu xiaochong
    private RelativeLayout left_menu_xiaochong;
    private MyGridView left_menu_xiaochong_content;
    private ImageView left_menu_xiaochong_image;


    // LeftMenu huore
    private RelativeLayout left_menu_huore;
    private MyGridView left_menu_huore_content;
    private ImageView left_menu_huore_image;

    // LeftMenu 地方
    private RelativeLayout left_menu_location;
    private MyGridView left_menu_location_content;
    private ImageView left_menu_location_image;

    // LeftMenu ALL
    private RelativeLayout left_menu_all;
    private MyGridView left_menu_all_content;
    private ImageView left_menu_all_image;

    private RelativeLayout menu_search;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.leftmenu, null);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        context = getActivity();
        super.onCreate(savedInstanceState);
    }

    private BitmapUtils bitmapUtils;
    private SharedPreferences sp;

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        sp = getActivity().getSharedPreferences("menuconfig", Context.MODE_PRIVATE);
        initLedfMenu();
        fillData("2");
        fillData("3");
        fillData("4");
        fillData("572");
        fillData(Address.HR);
        fillData(Address.LOCATION);
        fillData(Address.ALL);

        initBitmap();

        // 初始化我的关注集合
        super.onActivityCreated(savedInstanceState);
    }

    private void initBenDi() {
        left_menu_wangxingren_content.setAdapter(wxrA);
        wxrA.notifyDataSetChanged();

        left_menu_miaoxingren_content.setAdapter(mxrA);
        mxrA.notifyDataSetChanged();

        left_menu_shuizu_content.setAdapter(szA);
        szA.notifyDataSetChanged();

        left_menu_xiaochong_content.setAdapter(xcA);
        xcA.notifyDataSetChanged();

        left_menu_huore_content.setAdapter(hrA);
        hrA.notifyDataSetChanged();

        left_menu_location_content.setAdapter(locationA);
        locationA.notifyDataSetChanged();

        left_menu_all_content.setAdapter(allA);
        allA.notifyDataSetChanged();


    }

    private List<ClubC> top;

    private void initAttention() {
        attention = new LinkedList<ClubC>();
        if (!sp.getString("top", "").equals("")) {
            ClubCInfo topinfo = JSON.parseObject(sp.getString("top", ""), ClubCInfo.class);
            top = topinfo.getArray();
            attention.addAll(top);
        }
        attention.addLast(new ClubC("1000", "添加", "添加", R.drawable.left_menu_add, "111"));
        attentionAdapter = new AttentionAdapter(context, attention);
        left_menu_guanzhu_content.setAdapter(attentionAdapter);
    }

    private void initBitmap() {
        bitmapUtils = BitmapHelp.getBitmapUtils(getActivity());
        bitmapUtils.configDefaultLoadingImage(R.drawable.icon);
        bitmapUtils.configDefaultLoadFailedImage(R.drawable.icon);
        bitmapUtils.configDefaultBitmapConfig(Bitmap.Config.RGB_565);
    }

    private void initLedfMenu() {
        // 初始化 我的关注
        left_menu_guanzhu = (RelativeLayout) getView().findViewById(R.id.left_menu_guanzhu);
        left_menu_guanzhu_content =
                (MyGridView) getView().findViewById(R.id.left_menu_guanzhu_content);
        left_menu_guanzhu_content.setVisibility(View.VISIBLE);
        left_menu_guanzhu_image = (ImageView) getView().findViewById(R.id.left_menu_guanzhu_image);
        left_menu_guanzhu_image.setImageResource(R.drawable.xiala_ok);
        left_menu_guanzhu.setBackgroundResource(R.color.transparent);
        left_menu_guanzhu.setOnClickListener(this);

        // 初始化 旺星人
        left_menu_wangxingren_content =
                (MyGridView) getView().findViewById(R.id.left_menu_wangxingren_content);
        left_menu_wangxingren_content.setVisibility(View.GONE);
        left_menu_wangxingren = (RelativeLayout) getView().findViewById(R.id.left_menu_wangxingren);
        left_menu_wangxingren_image =
                (ImageView) getView().findViewById(R.id.left_menu_wangxingren_image);
        left_menu_wangxingren.setOnClickListener(this);

        // 初始化miaoxingren
        left_menu_miaoxingren_content =
                (MyGridView) getView().findViewById(R.id.left_menu_miaoxingren_content);
        left_menu_miaoxingren_content.setVisibility(View.GONE);
        left_menu_miaoxingren = (RelativeLayout) getView().findViewById(R.id.left_menu_miaoxingren);
        left_menu_miaoxingren_image =
                (ImageView) getView().findViewById(R.id.left_menu_miaoxingren_image);
        left_menu_miaoxingren.setOnClickListener(this);

        // 初始化水族俱乐部
        left_menu_shuizu_content =
                (MyGridView) getView().findViewById(R.id.left_menu_shuizu_content);
        left_menu_shuizu_content.setVisibility(View.GONE);
        left_menu_shuizu = (RelativeLayout) getView().findViewById(R.id.left_menu_shuizu);
        left_menu_shuizu_image = (ImageView) getView().findViewById(R.id.left_menu_shuizu_image);
        left_menu_shuizu.setOnClickListener(this);

        // 初始化小宠

        left_menu_xiaochong_content =
                (MyGridView) getView().findViewById(R.id.left_menu_xiaochong_content);
        left_menu_xiaochong_content.setVisibility(View.GONE);
        left_menu_xiaochong = (RelativeLayout) getView().findViewById(R.id.left_menu_xiaochong);
        left_menu_xiaochong_image =
                (ImageView) getView().findViewById(R.id.left_menu_xiaochong_image);
        left_menu_xiaochong.setOnClickListener(this);

        // 火热
        left_menu_huore_content = (MyGridView) getView().findViewById(R.id.left_menu_huore_content);
        left_menu_huore_content.setVisibility(View.GONE);
        left_menu_huore = (RelativeLayout) getView().findViewById(R.id.left_menu_huore);
        left_menu_huore_image = (ImageView) getView().findViewById(R.id.left_menu_huore_image);
        left_menu_huore.setOnClickListener(this);


        // 地方
        left_menu_location_content =
                (MyGridView) getView().findViewById(R.id.left_menu_location_content);
        left_menu_location_content.setVisibility(View.GONE);
        left_menu_location = (RelativeLayout) getView().findViewById(R.id.left_menu_location);
        left_menu_location_image =
                (ImageView) getView().findViewById(R.id.left_menu_location_image);
        left_menu_location.setOnClickListener(this);

        // 地方
        left_menu_all_content = (MyGridView) getView().findViewById(R.id.left_menu_all_content);
        left_menu_all_content.setVisibility(View.GONE);
        left_menu_all = (RelativeLayout) getView().findViewById(R.id.left_menu_all);
        left_menu_all_image = (ImageView) getView().findViewById(R.id.left_menu_all_image);
        left_menu_all.setOnClickListener(this);



        menu_search = (RelativeLayout) getView().findViewById(R.id.menu_search);
        menu_search.setOnClickListener(this);


        setOnItemClick();
    }

    private void setOnItemClick() {
        final Intent intent = new Intent(context, MyClubActivity.class);
        left_menu_guanzhu_content.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (position + 1 == attention.size()) {

                    Intent intent = new Intent(context, MyAttentionActivity.class);
                    startActivityForResult(intent, 200);
                } else {
                    intent.putExtra("name", attention.get(position).getName());
                    intent.putExtra("fId", attention.get(position).getFid());
                    startActivity(intent);
                }
            }
        });
        left_menu_guanzhu_content.setOnItemLongClickListener(new OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                attentionAdapter.notifyDataSetChanged();
                return true;
            }
        });
        left_menu_wangxingren_content.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                intent.putExtra("name", wxrA.getClubs().get(position).getLname());
                intent.putExtra("fId", wxrA.getClubs().get(position).getFid());
                startActivity(intent);
            }
        });

        left_menu_miaoxingren_content.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                intent.putExtra("name", mxrA.getClubs().get(position).getLname());
                intent.putExtra("fId", mxrA.getClubs().get(position).getFid());
                startActivity(intent);
            }
        });
        left_menu_shuizu_content.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                intent.putExtra("name", szA.getClubs().get(position).getLname());
                intent.putExtra("fId", szA.getClubs().get(position).getFid());
                startActivity(intent);
            }
        });
        left_menu_xiaochong_content.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                intent.putExtra("name", xcA.getClubs().get(position).getLname());
                intent.putExtra("fId", xcA.getClubs().get(position).getFid());
                startActivity(intent);
            }
        });
        left_menu_huore_content.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                intent.putExtra("name", hrA.getClubs().get(position).getLname());
                intent.putExtra("fId", hrA.getClubs().get(position).getFid());
                startActivity(intent);
            }
        });
        left_menu_location_content.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                intent.putExtra("name", locationA.getClubs().get(position).getLname());
                intent.putExtra("fId", locationA.getClubs().get(position).getFid());
                startActivity(intent);
            }
        });
        left_menu_all_content.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                intent.putExtra("name", allA.getClubs().get(position).getLname());
                intent.putExtra("fId", allA.getClubs().get(position).getFid());
                startActivity(intent);
            }
        });
    }

    private final NewAdapter wxrA = new NewAdapter(ConstantsValue.getWxrInfo());
    private final NewAdapter mxrA = new NewAdapter(ConstantsValue.getMxrInfo());
    private final NewAdapter szA = new NewAdapter(ConstantsValue.getSzInfo());
    private final NewAdapter xcA = new NewAdapter(ConstantsValue.getXcInfo());
    private final NewAdapter hrA = new NewAdapter(ConstantsValue.getHrInfo());
    private final NewAdapter locationA = new NewAdapter(ConstantsValue.getLocationInfo());
    private final NewAdapter allA = new NewAdapter(ConstantsValue.getAllInfo());



    public class NewAdapter extends BaseAdapter {
        private final List<ClubC> clubs;

        public NewAdapter(List<ClubC> clubs) {
            super();
            this.clubs = clubs;
        }

        @Override
        public int getCount() {
            return clubs.size();
        }

        public List<ClubC> getClubs() {
            return clubs;
        }

        @Override
        public Object getItem(int position) {
            return clubs.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
            if (convertView == null) {
                convertView = View.inflate(getActivity(), R.layout.left_nemu_list, null);
                holder = new ViewHolder();
                holder.iv_item_list = (CircleImageView) convertView.findViewById(R.id.iv_item_list);
                holder.tv_item_list = (TextView) convertView.findViewById(R.id.tv_item_list);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            holder.iv_item_list.setImageResource(clubs.get(position).getId());
            holder.tv_item_list.setText(clubs.get(position).getName());
            return convertView;
        }
    }
    private class ViewHolder {
        CircleImageView iv_item_list;
        TextView tv_item_list;
    }

    @SuppressLint("ShowToast")
    public void fillData(final String fid) {
        RequestParams params = new RequestParams();
        params.put("fid", fid);
        AddClient.get(Address.CLUB, params, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, String content) {
                try {
                    if (fid.equals(Address.WXR)) {
                        ClubInfo info = null;
                        try {
                            info = JSON.parseObject(content, ClubInfo.class);
                        } catch (Exception e) {
                        }
                        if (null == info) {
                            Toast.makeText(context, R.string.get_error_data, 0).show();
                            return;
                        }
                        List<Club> array = info.getArray();
                        for (Club club : array) {
                            club.setPud(Address.WXR);
                        }
                        String jsonString = JSON.toJSONString(array);
                        Editor editor = sp.edit();
                        editor.putString("wxr", "{" + "\"array\":" + jsonString + "}");
                        editor.commit();
                        // wxrAdapter = new ClubAdapter(info);
                        // left_menu_wangxingren_content.setAdapter(wxrAdapter);
                        // wxrAdapter.notifyDataSetChanged();
                        info = null;
                    }
                    if (fid.equals(Address.MXR)) {
                        ClubInfo info = null;
                        try {
                            info = JSON.parseObject(content, ClubInfo.class);
                        } catch (Exception e) {
                        }
                        if (null == info) {
                            Toast.makeText(context, R.string.get_error_data, 0).show();
                            return;
                        }
                        List<Club> array = info.getArray();
                        for (Club club : array) {
                            club.setPud(Address.MXR);
                        }
                        String jsonString = JSON.toJSONString(array);
                        Editor editor = sp.edit();
                        editor.putString("mxr", "{" + "\"array\":" + jsonString + "}");
                        editor.commit();
                        // mxrAdapter = new ClubAdapter(info);
                        // left_menu_miaoxingren_content.setAdapter(mxrAdapter);
                        // mxrAdapter.notifyDataSetChanged();
                        info = null;
                    }
                    if (fid.equals(Address.SZ)) {
                        ClubInfo info = null;
                        try {
                            info = JSON.parseObject(content, ClubInfo.class);
                        } catch (Exception e) {
                        }
                        if (null == info) {
                            Toast.makeText(context, R.string.get_error_data, 0).show();
                            return;
                        }
                        List<Club> array = info.getArray();
                        for (Club club : array) {
                            club.setPud(Address.SZ);
                        }
                        String jsonString = JSON.toJSONString(array);
                        Editor editor = sp.edit();
                        editor.putString("sz", "{" + "\"array\":" + jsonString + "}");
                        editor.commit();
                        // szAdapter = new ClubAdapter(info);
                        // left_menu_shuizu_content.setAdapter(szAdapter);
                        // szAdapter.notifyDataSetChanged();
                        info = null;
                    }
                    if (fid.equals(Address.XC)) {
                        ClubInfo info = null;
                        try {
                            info = JSON.parseObject(content, ClubInfo.class);
                        } catch (Exception e) {
                        }
                        if (null == info) {
                            Toast.makeText(context, R.string.get_error_data, 0).show();
                            return;
                        }
                        List<Club> array = info.getArray();
                        for (Club club : array) {
                            club.setPud(Address.XC);
                        }
                        String jsonString = JSON.toJSONString(array);
                        Editor editor = sp.edit();
                        editor.putString("xc", "{" + "\"array\":" + jsonString + "}");
                        editor.commit();
                        // xcAdapter = new ClubAdapter(info);
                        // left_menu_xiaochong_content.setAdapter(xcAdapter);
                        // xcAdapter.notifyDataSetChanged();
                        info = null;
                    }
                    if (fid.equals(Address.HR)) {
                        ClubInfo info = JSON.parseObject(content, ClubInfo.class);
                        List<Club> array = info.getArray();
                        for (Club club : array) {
                            club.setPud(Address.HR);
                        }
                        String jsonString = JSON.toJSONString(array);
                        Editor editor = sp.edit();
                        editor.putString("hr", "{" + "\"array\":" + jsonString + "}");
                        editor.commit();
                        // xcAdapter = new ClubAdapter(info);
                        // left_menu_xiaochong_content.setAdapter(xcAdapter);
                        // xcAdapter.notifyDataSetChanged();
                        info = null;
                    }
                    if (fid.equals(Address.LOCATION)) {
                        ClubInfo info = JSON.parseObject(content, ClubInfo.class);
                        List<Club> array = info.getArray();
                        for (Club club : array) {
                            club.setPud(Address.LOCATION);
                        }
                        String jsonString = JSON.toJSONString(array);
                        Editor editor = sp.edit();
                        editor.putString("location", "{" + "\"array\":" + jsonString + "}");
                        editor.commit();
                        // xcAdapter = new ClubAdapter(info);
                        // left_menu_xiaochong_content.setAdapter(xcAdapter);
                        // xcAdapter.notifyDataSetChanged();
                        info = null;
                    }
                    if (fid.equals(Address.ALL)) {
                        ClubInfo info = JSON.parseObject(content, ClubInfo.class);
                        List<Club> array = info.getArray();
                        for (Club club : array) {
                            club.setPud(Address.ALL);
                        }
                        String jsonString = JSON.toJSONString(array);
                        Editor editor = sp.edit();
                        editor.putString("all", "{" + "\"array\":" + jsonString + "}");
                        editor.commit();
                        // xcAdapter = new ClubAdapter(info);
                        // left_menu_xiaochong_content.setAdapter(xcAdapter);
                        // xcAdapter.notifyDataSetChanged();
                        info = null;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }

                super.onSuccess(statusCode, content);
            }

            @Override
            public void onFailure(Throwable error, String content) {
                super.onFailure(error, content);
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.left_menu_guanzhu:
                left_menu_wangxingren_content.performClick();
                left_menu_miaoxingren_content.performClick();
                left_menu_shuizu_content.performClick();
                left_menu_xiaochong_content.performClick();
                left_menu_huore_content.performClick();
                left_menu_location_content.performClick();
                left_menu_all_content.performClick();

                left_menu_wangxingren_content.setVisibility(View.GONE);
                left_menu_miaoxingren_content.setVisibility(View.GONE);
                left_menu_shuizu_content.setVisibility(View.GONE);
                left_menu_xiaochong_content.setVisibility(View.GONE);
                left_menu_huore_content.setVisibility(View.GONE);
                left_menu_location_content.setVisibility(View.GONE);
                left_menu_all_content.setVisibility(View.GONE);

                left_menu_wangxingren_image.setImageResource(R.drawable.xiala_false);
                left_menu_miaoxingren_image.setImageResource(R.drawable.xiala_false);
                left_menu_shuizu_image.setImageResource(R.drawable.xiala_false);
                left_menu_xiaochong_image.setImageResource(R.drawable.xiala_false);
                left_menu_huore_image.setImageResource(R.drawable.xiala_false);
                left_menu_location_image.setImageResource(R.drawable.xiala_false);
                left_menu_all_image.setImageResource(R.drawable.xiala_false);

                left_menu_miaoxingren.setBackgroundResource(R.color.transparent);
                left_menu_wangxingren.setBackgroundResource(R.color.transparent);
                left_menu_shuizu.setBackgroundResource(R.color.transparent);
                left_menu_xiaochong.setBackgroundResource(R.color.transparent);
                left_menu_huore.setBackgroundResource(R.color.transparent);
                left_menu_location.setBackgroundResource(R.color.transparent);
                left_menu_all.setBackgroundResource(R.color.transparent);

                int visibility = left_menu_guanzhu_content.getVisibility();
                if (visibility == View.GONE) {
                    left_menu_guanzhu.setBackgroundResource(R.color.transparent);
                    left_menu_guanzhu_content.setVisibility(View.VISIBLE);
                    left_menu_guanzhu_image.setImageResource(R.drawable.xiala_ok);
                } else {
                    left_menu_guanzhu.setBackgroundResource(R.color.transparent);
                    left_menu_guanzhu_content.setVisibility(View.GONE);
                    left_menu_guanzhu_image.setImageResource(R.drawable.xiala_false);
                }
                break;
            case R.id.left_menu_wangxingren:

                left_menu_guanzhu_content.performClick();
                left_menu_miaoxingren_content.performClick();
                left_menu_shuizu_content.performClick();
                left_menu_xiaochong_content.performClick();
                left_menu_huore_content.performClick();
                left_menu_location_content.performClick();
                left_menu_all_content.performClick();

                left_menu_guanzhu_content.setVisibility(View.GONE);
                left_menu_miaoxingren_content.setVisibility(View.GONE);
                left_menu_shuizu_content.setVisibility(View.GONE);
                left_menu_xiaochong_content.setVisibility(View.GONE);
                left_menu_huore_content.setVisibility(View.GONE);
                left_menu_location_content.setVisibility(View.GONE);
                left_menu_all_content.setVisibility(View.GONE);

                left_menu_guanzhu_image.setImageResource(R.drawable.xiala_false);
                left_menu_miaoxingren_image.setImageResource(R.drawable.xiala_false);
                left_menu_shuizu_image.setImageResource(R.drawable.xiala_false);
                left_menu_xiaochong_image.setImageResource(R.drawable.xiala_false);
                left_menu_huore_image.setImageResource(R.drawable.xiala_false);
                left_menu_location_image.setImageResource(R.drawable.xiala_false);
                left_menu_all_image.setImageResource(R.drawable.xiala_false);

                // left_menu_guanzhu.setBackgroundResource(R.color.transparent);
                // left_menu_miaoxingren.setBackgroundResource(R.color.transparent);
                // left_menu_wangxingren.setBackgroundResource(R.color.transparent);
                // left_menu_shuizu.setBackgroundResource(R.color.transparent);
                // left_menu_xiaochong.setBackgroundResource(R.color.transparent);
                // left_menu_huore.setBackgroundResource(R.color.transparent);
                // left_menu_location.setBackgroundResource(R.color.transparent);
                // left_menu_all.setBackgroundResource(R.color.transparent);

                int visibility2 = left_menu_wangxingren_content.getVisibility();
                if (visibility2 == View.GONE) {
                    left_menu_wangxingren.setBackgroundResource(R.color.transparent);
                    left_menu_wangxingren_content.setVisibility(View.VISIBLE);
                    left_menu_wangxingren_image.setImageResource(R.drawable.xiala_ok);
                } else {
                    left_menu_wangxingren.setBackgroundResource(R.color.transparent);
                    left_menu_wangxingren_content.setVisibility(View.GONE);
                    left_menu_wangxingren_image.setImageResource(R.drawable.xiala_false);
                }
                break;
            case R.id.left_menu_miaoxingren:
                left_menu_wangxingren_content.performClick();
                left_menu_guanzhu_content.performClick();
                left_menu_shuizu_content.performClick();
                left_menu_xiaochong_content.performClick();
                left_menu_huore_content.performClick();
                left_menu_location_content.performClick();
                left_menu_all_content.performClick();

                left_menu_wangxingren_content.setVisibility(View.GONE);
                left_menu_guanzhu_content.setVisibility(View.GONE);
                left_menu_shuizu_content.setVisibility(View.GONE);
                left_menu_xiaochong_content.setVisibility(View.GONE);
                left_menu_huore_content.setVisibility(View.GONE);
                left_menu_location_content.setVisibility(View.GONE);
                left_menu_all_content.setVisibility(View.GONE);

                left_menu_wangxingren_image.setImageResource(R.drawable.xiala_false);
                left_menu_guanzhu_image.setImageResource(R.drawable.xiala_false);
                left_menu_shuizu_image.setImageResource(R.drawable.xiala_false);
                left_menu_xiaochong_image.setImageResource(R.drawable.xiala_false);
                left_menu_huore_image.setImageResource(R.drawable.xiala_false);
                left_menu_location_image.setImageResource(R.drawable.xiala_false);
                left_menu_all_image.setImageResource(R.drawable.xiala_false);

                // left_menu_guanzhu.setBackgroundResource(R.color.transparent);
                // left_menu_miaoxingren.setBackgroundResource(R.color.transparent);
                // left_menu_wangxingren.setBackgroundResource(R.color.transparent);
                // left_menu_shuizu.setBackgroundResource(R.color.transparent);
                // left_menu_xiaochong.setBackgroundResource(R.color.transparent);
                // left_menu_huore.setBackgroundResource(R.color.transparent);
                // left_menu_location.setBackgroundResource(R.color.transparent);
                // left_menu_all.setBackgroundResource(R.color.transparent);

                int visibility3 = left_menu_miaoxingren_content.getVisibility();
                if (visibility3 == View.GONE) {
                    left_menu_miaoxingren.setBackgroundResource(R.color.transparent);
                    left_menu_miaoxingren_content.setVisibility(View.VISIBLE);
                    left_menu_miaoxingren_image.setImageResource(R.drawable.xiala_ok);
                } else {
                    left_menu_miaoxingren.setBackgroundResource(R.color.transparent);
                    left_menu_miaoxingren_content.setVisibility(View.GONE);
                    left_menu_miaoxingren_image.setImageResource(R.drawable.xiala_false);
                }
                break;
            case R.id.left_menu_shuizu:
                left_menu_wangxingren_content.performClick();
                left_menu_guanzhu_content.performClick();
                left_menu_miaoxingren_content.performClick();
                left_menu_xiaochong_content.performClick();
                left_menu_huore_content.performClick();
                left_menu_location_content.performClick();
                left_menu_all_content.performClick();

                left_menu_wangxingren_content.setVisibility(View.GONE);
                left_menu_guanzhu_content.setVisibility(View.GONE);
                left_menu_miaoxingren_content.setVisibility(View.GONE);
                left_menu_xiaochong_content.setVisibility(View.GONE);
                left_menu_huore_content.setVisibility(View.GONE);
                left_menu_location_content.setVisibility(View.GONE);
                left_menu_all_content.setVisibility(View.GONE);


                left_menu_wangxingren_image.setImageResource(R.drawable.xiala_false);
                left_menu_guanzhu_image.setImageResource(R.drawable.xiala_false);
                left_menu_miaoxingren_image.setImageResource(R.drawable.xiala_false);
                left_menu_xiaochong_image.setImageResource(R.drawable.xiala_false);
                left_menu_huore_image.setImageResource(R.drawable.xiala_false);
                left_menu_location_image.setImageResource(R.drawable.xiala_false);
                left_menu_all_image.setImageResource(R.drawable.xiala_false);

                // left_menu_guanzhu.setBackgroundResource(R.color.transparent);
                // left_menu_miaoxingren.setBackgroundResource(R.color.transparent);
                // left_menu_wangxingren.setBackgroundResource(R.color.transparent);
                // left_menu_shuizu.setBackgroundResource(R.color.transparent);
                // left_menu_xiaochong.setBackgroundResource(R.color.transparent);
                // left_menu_huore.setBackgroundResource(R.color.transparent);
                // left_menu_location.setBackgroundResource(R.color.transparent);
                // left_menu_all.setBackgroundResource(R.color.transparent);

                int visibility4 = left_menu_shuizu_content.getVisibility();
                if (visibility4 == View.GONE) {
                    left_menu_shuizu.setBackgroundResource(R.color.transparent);
                    left_menu_shuizu_content.setVisibility(View.VISIBLE);
                    left_menu_shuizu_image.setImageResource(R.drawable.xiala_ok);
                } else {
                    left_menu_shuizu.setBackgroundResource(R.color.transparent);
                    left_menu_shuizu_content.setVisibility(View.GONE);
                    left_menu_shuizu_image.setImageResource(R.drawable.xiala_false);
                }
                break;
            case R.id.left_menu_xiaochong:
                left_menu_wangxingren_content.performClick();
                left_menu_guanzhu_content.performClick();
                left_menu_miaoxingren_content.performClick();
                left_menu_shuizu_content.performClick();
                left_menu_huore_content.performClick();
                left_menu_location_content.performClick();
                left_menu_all_content.performClick();

                left_menu_wangxingren_content.setVisibility(View.GONE);
                left_menu_guanzhu_content.setVisibility(View.GONE);
                left_menu_miaoxingren_content.setVisibility(View.GONE);
                left_menu_shuizu_content.setVisibility(View.GONE);
                left_menu_huore_content.setVisibility(View.GONE);
                left_menu_location_content.setVisibility(View.GONE);
                left_menu_all_content.setVisibility(View.GONE);

                left_menu_wangxingren_image.setImageResource(R.drawable.xiala_false);
                left_menu_guanzhu_image.setImageResource(R.drawable.xiala_false);
                left_menu_miaoxingren_image.setImageResource(R.drawable.xiala_false);
                left_menu_shuizu_image.setImageResource(R.drawable.xiala_false);
                left_menu_huore_image.setImageResource(R.drawable.xiala_false);
                left_menu_location_image.setImageResource(R.drawable.xiala_false);
                left_menu_all_image.setImageResource(R.drawable.xiala_false);

                // left_menu_guanzhu.setBackgroundResource(R.color.transparent);
                // left_menu_miaoxingren.setBackgroundResource(R.color.transparent);
                // left_menu_wangxingren.setBackgroundResource(R.color.transparent);
                // left_menu_shuizu.setBackgroundResource(R.color.transparent);
                // left_menu_huore.setBackgroundResource(R.color.transparent);
                // left_menu_location.setBackgroundResource(R.color.transparent);
                // left_menu_all.setBackgroundResource(R.color.transparent);

                int visibility5 = left_menu_xiaochong_content.getVisibility();

                if (visibility5 == View.GONE) {
                    left_menu_xiaochong.setBackgroundResource(R.color.transparent);
                    left_menu_xiaochong_content.setVisibility(View.VISIBLE);
                    left_menu_xiaochong_image.setImageResource(R.drawable.xiala_ok);
                } else {
                    left_menu_xiaochong_content.setVisibility(View.GONE);
                    left_menu_xiaochong.setBackgroundResource(R.color.transparent);
                    left_menu_xiaochong_image.setImageResource(R.drawable.xiala_false);
                }
                break;
            case R.id.left_menu_huore:
                left_menu_wangxingren_content.performClick();
                left_menu_guanzhu_content.performClick();
                left_menu_miaoxingren_content.performClick();
                left_menu_shuizu_content.performClick();
                left_menu_xiaochong_content.performClick();
                left_menu_location_content.performClick();
                left_menu_all_content.performClick();

                left_menu_wangxingren_content.setVisibility(View.GONE);
                left_menu_guanzhu_content.setVisibility(View.GONE);
                left_menu_miaoxingren_content.setVisibility(View.GONE);
                left_menu_shuizu_content.setVisibility(View.GONE);
                left_menu_xiaochong_content.setVisibility(View.GONE);
                left_menu_location_content.setVisibility(View.GONE);
                left_menu_all_content.setVisibility(View.GONE);

                left_menu_wangxingren_image.setImageResource(R.drawable.xiala_false);
                left_menu_guanzhu_image.setImageResource(R.drawable.xiala_false);
                left_menu_miaoxingren_image.setImageResource(R.drawable.xiala_false);
                left_menu_shuizu_image.setImageResource(R.drawable.xiala_false);
                left_menu_xiaochong_image.setImageResource(R.drawable.xiala_false);
                left_menu_location_image.setImageResource(R.drawable.xiala_false);
                left_menu_all_image.setImageResource(R.drawable.xiala_false);

                // left_menu_guanzhu.setBackgroundResource(R.color.transparent);
                // left_menu_miaoxingren.setBackgroundResource(R.color.transparent);
                // left_menu_wangxingren.setBackgroundResource(R.color.transparent);
                // left_menu_shuizu.setBackgroundResource(R.color.transparent);
                // left_menu_xiaochong.setBackgroundResource(R.color.transparent);
                // left_menu_location.setBackgroundResource(R.color.transparent);
                // left_menu_all.setBackgroundResource(R.color.transparent);

                int visibility6 = left_menu_huore_content.getVisibility();

                if (visibility6 == View.GONE) {
                    left_menu_huore.setBackgroundResource(R.color.transparent);
                    left_menu_huore_content.setVisibility(View.VISIBLE);
                    left_menu_huore_image.setImageResource(R.drawable.xiala_ok);
                } else {
                    left_menu_huore_content.setVisibility(View.GONE);
                    left_menu_huore.setBackgroundResource(R.color.transparent);
                    left_menu_huore_image.setImageResource(R.drawable.xiala_false);
                }
                break;
            case R.id.left_menu_location:
                left_menu_wangxingren_content.performClick();
                left_menu_guanzhu_content.performClick();
                left_menu_miaoxingren_content.performClick();
                left_menu_shuizu_content.performClick();
                left_menu_xiaochong_content.performClick();
                left_menu_huore_content.performClick();
                left_menu_all_content.performClick();

                left_menu_wangxingren_content.setVisibility(View.GONE);
                left_menu_guanzhu_content.setVisibility(View.GONE);
                left_menu_miaoxingren_content.setVisibility(View.GONE);
                left_menu_shuizu_content.setVisibility(View.GONE);
                left_menu_xiaochong_content.setVisibility(View.GONE);
                left_menu_huore_content.setVisibility(View.GONE);
                left_menu_all_content.setVisibility(View.GONE);

                left_menu_wangxingren_image.setImageResource(R.drawable.xiala_false);
                left_menu_guanzhu_image.setImageResource(R.drawable.xiala_false);
                left_menu_miaoxingren_image.setImageResource(R.drawable.xiala_false);
                left_menu_shuizu_image.setImageResource(R.drawable.xiala_false);
                left_menu_xiaochong_image.setImageResource(R.drawable.xiala_false);
                left_menu_huore_image.setImageResource(R.drawable.xiala_false);
                left_menu_all_image.setImageResource(R.drawable.xiala_false);

                // left_menu_guanzhu.setBackgroundResource(R.color.transparent);
                // left_menu_miaoxingren.setBackgroundResource(R.color.transparent);
                // left_menu_wangxingren.setBackgroundResource(R.color.transparent);
                // left_menu_shuizu.setBackgroundResource(R.color.transparent);
                // left_menu_xiaochong.setBackgroundResource(R.color.transparent);
                // left_menu_huore.setBackgroundResource(R.color.transparent);
                // left_menu_all.setBackgroundResource(R.color.transparent);

                int visibility7 = left_menu_location_content.getVisibility();

                if (visibility7 == View.GONE) {
                    left_menu_location.setBackgroundResource(R.color.transparent);
                    left_menu_location_content.setVisibility(View.VISIBLE);
                    left_menu_location_image.setImageResource(R.drawable.xiala_ok);
                } else {
                    left_menu_location_content.setVisibility(View.GONE);
                    left_menu_location.setBackgroundResource(R.color.transparent);
                    left_menu_location_image.setImageResource(R.drawable.xiala_false);
                }
                break;
            case R.id.left_menu_all:
                left_menu_wangxingren_content.performClick();
                left_menu_guanzhu_content.performClick();
                left_menu_miaoxingren_content.performClick();
                left_menu_shuizu_content.performClick();
                left_menu_xiaochong_content.performClick();
                left_menu_huore_content.performClick();
                left_menu_location_content.performClick();

                left_menu_wangxingren_content.setVisibility(View.GONE);
                left_menu_guanzhu_content.setVisibility(View.GONE);
                left_menu_miaoxingren_content.setVisibility(View.GONE);
                left_menu_shuizu_content.setVisibility(View.GONE);
                left_menu_xiaochong_content.setVisibility(View.GONE);
                left_menu_huore_content.setVisibility(View.GONE);
                left_menu_location_content.setVisibility(View.GONE);

                left_menu_wangxingren_image.setImageResource(R.drawable.xiala_false);
                left_menu_guanzhu_image.setImageResource(R.drawable.xiala_false);
                left_menu_miaoxingren_image.setImageResource(R.drawable.xiala_false);
                left_menu_shuizu_image.setImageResource(R.drawable.xiala_false);
                left_menu_xiaochong_image.setImageResource(R.drawable.xiala_false);
                left_menu_huore_image.setImageResource(R.drawable.xiala_false);
                left_menu_location_image.setImageResource(R.drawable.xiala_false);

                // left_menu_guanzhu.setBackgroundResource(R.color.transparent);
                // left_menu_miaoxingren.setBackgroundResource(R.color.transparent);
                // left_menu_wangxingren.setBackgroundResource(R.color.transparent);
                // left_menu_shuizu.setBackgroundResource(R.color.transparent);
                // left_menu_xiaochong.setBackgroundResource(R.color.transparent);
                // left_menu_huore.setBackgroundResource(R.color.transparent);
                // left_menu_location.setBackgroundResource(R.color.transparent);

                int visibility8 = left_menu_all_content.getVisibility();

                if (visibility8 == View.GONE) {
                    left_menu_all.setBackgroundResource(R.color.transparent);
                    left_menu_all_content.setVisibility(View.VISIBLE);
                    left_menu_all_image.setImageResource(R.drawable.xiala_ok);
                } else {
                    left_menu_all_content.setVisibility(View.GONE);
                    left_menu_all.setBackgroundResource(R.color.transparent);
                    left_menu_all_image.setImageResource(R.drawable.xiala_false);
                }
                break;
            case R.id.menu_search:
                Intent search = new Intent(context, Search2Activity.class);
                startActivity(search);
                break;
            default:
                break;
        }
    }


}
